package com.example.hao.flowercityfm.HFAdapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.hao.flowercityfm.HFAdapter.ViewHolder.BaseTypeViewHolder;
import com.example.hao.flowercityfm.HFAdapter.ViewHolder.Type1ViewHolder;
import com.example.hao.flowercityfm.HFAdapter.ViewHolder.Type3ViewHolder;
import com.example.hao.flowercityfm.HFAdapter.ViewHolder.Type4ViewHolder;
import com.example.hao.flowercityfm.HFAdapter.ViewHolder.Type5ViewHolder;
import com.example.hao.flowercityfm.HFAdapter.ViewHolder.Type6ViewHolder;
import com.example.hao.flowercityfm.HFAdapter.ViewHolder.UnknownTypeViewHolder;
import com.example.hao.flowercityfm.R;
import com.example.hao.flowercityfm.pojo.HomeFragmentData;

import butterknife.BindView;

public class HomeDataAdapter extends RecyclerView.Adapter {

    private Context context;

    private HomeFragmentData homeData;

    private static final String TAG = "HomeDataAdapter";

    public HomeDataAdapter(Context context) {

        this.context = context;
    }

    public void setHomeData(HomeFragmentData homeData) {
        this.homeData = homeData;
        notifyDataSetChanged();
    }

    @Override
    public int getItemViewType(int position) {
        HomeFragmentData.ListBean listBean = homeData.getList().get(position);
        return listBean.getModuleId();
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        LayoutInflater inflater = LayoutInflater.from(context);
        switch (viewType) {
            case MODEL_ID_0:
                return new Type1ViewHolder(context, inflater.inflate(R.layout.fragment_home_rotation, parent, false));
            case MODEL_ID_3:
                return new Type3ViewHolder(context, inflater.inflate(R.layout.fragment_home_type3, parent, false));
            case MODEL_ID_4:
                return new Type4ViewHolder(context, inflater.inflate(R.layout.fragment_home_type3, parent, false));
            case MODEL_ID_5:
                return new Type5ViewHolder(context, inflater.inflate(R.layout.fragment_home_type3, parent, false));
            case MODEL_ID_6:
                return new Type6ViewHolder(context, inflater.inflate(R.layout.fragment_home_type3, parent, false));
        }
        return new UnknownTypeViewHolder(context, inflater.inflate(R.layout.fragment_unknown_item, parent, false));
    }

    private static final int MODEL_ID_0 = 0;
    private static final int MODEL_ID_1 = 1;
    private static final int MODEL_ID_2 = 2;
    private static final int MODEL_ID_3 = 3;
    private static final int MODEL_ID_4 = 4;
    private static final int MODEL_ID_5 = 5;
    private static final int MODEL_ID_6 = 6;

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {

        BaseTypeViewHolder viewHolder = (BaseTypeViewHolder) holder;
        HomeFragmentData.ListBean listBean = homeData.getList().get(position);
        viewHolder.setData(listBean);
//        switch (position){
//            case 5:
//
//                break;
//        }
    }

    @Override
    public int getItemCount() {

//        Log.d(TAG, "getItemCount: "+homeData);
//        return homeData == null? 0: homeData.getList().size();
        return 19;

    }


}
